package tt.dz.appserver.mvc.manage;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;

import tt.dz.appserver.entity.model.ResultMappingEntity;
import tt.dz.appserver.entity.model.ServiceStation;
import tt.dz.appserver.service.business.ServiceStationService;
import tt.dz.appserver.util.Result;
import tt.dz.appserver.util.enums.Response;

/**
 * 服务网点管理
 * @author USER001
 *
 */

@RestController
@RequestMapping("/manage/serviceStation")
public class ServiceStationManager {

	/**服务网点管理*/
	@Resource
	ServiceStationService serviceStationService;
	
	/**
	 * 服务站点增加
	 **@param servicestationid		网点id
	 * @param servicestationname	网点名称	
	 * @param description			网点描述
	 * @param businesstime			营业时间
	 * @param contactphone			联系电话
	 * @param provinceid			省id
	 * @param cityid				市id
	 * @param areaid				区id
	 * @param outletsaddr			网点地址
	 * @param longitude				经度
	 * @param latitude				维度
	 * @param createtime			添加时间
	 * @param updatetime			最后修改时间
	 * @param operid				操作id
	 **@param validflag				有效标志
	 * @return
	 */
	@RequestMapping(value="/ServiceStationAdd",produces={"application/json;charset=utf-8"})

	public String servicestationadd(
		 	@RequestParam(value="servicestationname") String servicestationname,
			@RequestParam(value="description", required=false) String description,
			@RequestParam(value="businesstime") String businesstime,
			@RequestParam(value="contactphone") String contactphone,
			@RequestParam(value="provinceid") String provinceid,
			@RequestParam(value="cityid") String cityid,
			@RequestParam(value="areaid") String areaid,
			@RequestParam(value="outletsaddr") String outletsaddr,
			@RequestParam(value="longitude") String longitude,
			@RequestParam(value="latitude") String latitude,
			@RequestParam(value="operid") String operid) {
		//返回数据映射实体
		ResultMappingEntity resultMappingEntity = null;
		
		try {
			
			//添加反馈
			JSONObject resultObject = serviceStationService.servicestationadd(servicestationname, 
					description, businesstime, contactphone, provinceid, cityid, areaid, outletsaddr, 
					longitude, latitude, operid);
			
			String code = resultObject.getString("code");
			String msg = resultObject.getString("msg");
			
			if (Response.SUCCESS.getCode().equals(code)) {
				//返回参数拼接（删除resultObject对象中的code和msg再返回）
				resultObject.remove("code");
				resultObject.remove("msg");
				
				resultMappingEntity = Result.responseBody(code, msg, resultObject);
			}
			else {
				resultMappingEntity = Result.responseBody(code, msg);
			}			
			
		} catch(Exception e) {
			e.printStackTrace();
			//异常
			resultMappingEntity = Result.responseBody(Response.RUNTIME_ERROR.getCode(), Response.RUNTIME_ERROR.getMsg(), e.getMessage());
		}
		return resultMappingEntity.toString();
	}
	
	/**
	 * 服务站点删除
	 * @param servicestationid		网点id
	 **@param servicestationname	网点名称	
	 **@param description			网点描述
	 **@param businesstime			营业时间
	 **@param contactphone			联系电话
	 **@param provinceid			省id
	 **@param cityid				市id
	 **@param areaid				区id
	 **@param outletsaddr			网点地址
	 **@param longitude				经度
	 **@param latitude				维度
	 **@param createtime			添加时间
	 * @param updatetime			最后修改时间
	 * @param operid				操作id
	 **@param validflag				有效标志
	 * @return
	 */
	@RequestMapping(value="/ServiceStationDel",produces={"application/json;charset=utf-8"})

	public String servicestationdel(
		 	@RequestParam(value="servicestationid") String servicestationid,
			@RequestParam(value="operid") String operid) {
		//返回数据映射实体
		ResultMappingEntity resultMappingEntity = null;
		
		try {
			
			//添加反馈
			JSONObject resultObject = serviceStationService.servicestationdel(servicestationid, operid);
			
			String code = resultObject.getString("code");
			String msg = resultObject.getString("msg");
			
			if (Response.SUCCESS.getCode().equals(code)) {
				//返回参数拼接（删除resultObject对象中的code和msg再返回）
				resultObject.remove("code");
				resultObject.remove("msg");
				
				resultMappingEntity = Result.responseBody(code, msg, resultObject);
			}
			else {
				resultMappingEntity = Result.responseBody(code, msg);
			}			
			
		} catch(Exception e) {
			e.printStackTrace();
			//异常
			resultMappingEntity = Result.responseBody(Response.RUNTIME_ERROR.getCode(), Response.RUNTIME_ERROR.getMsg(), e.getMessage());
		}
		return resultMappingEntity.toString();
	}
	
	/**
	 * 服务站点更新
	 * @param servicestationid		网点id
	 * @param servicestationname	网点名称	
	 * @param description			网点描述
	 * @param businesstime			营业时间
	 * @param contactphone			联系电话
	 * @param provinceid			省id
	 * @param cityid				市id
	 * @param areaid				区id
	 * @param outletsaddr			网点地址
	 * @param longitude				经度
	 * @param latitude				维度
	 **@param createtime			添加时间
	 **@param updatetime			最后修改时间
	 * @param operid				操作id
	 **@param validflag				有效标志
	 * @return
	 */
	@RequestMapping(value="/ServiceStationUpdate",produces={"application/json;charset=utf-8"})

	public String servicestationupdate(
		 	@RequestParam(value="servicestationid") String servicestationid,
		 	@RequestParam(value="servicestationname", required=false) String servicestationname,
			@RequestParam(value="description", required=false) String description,
			@RequestParam(value="businesstime", required=false) String businesstime,
			@RequestParam(value="contactphone", required=false) String contactphone,
			@RequestParam(value="provinceid", required=false) String provinceid,
			@RequestParam(value="cityid", required=false) String cityid,
			@RequestParam(value="areaid", required=false) String areaid,
			@RequestParam(value="outletsaddr", required=false) String outletsaddr,
			@RequestParam(value="longitude", required=false) String longitude,
			@RequestParam(value="latitude", required=false) String latitude,
			@RequestParam(value="operid") String operid) {
		//返回数据映射实体
		ResultMappingEntity resultMappingEntity = null;
		
		try {
			
			//添加反馈
			JSONObject resultObject = serviceStationService.servicestationupdate(servicestationid, servicestationname, 
					description, businesstime, contactphone, provinceid, cityid, areaid, outletsaddr, 
					longitude, latitude, operid);
			
			String code = resultObject.getString("code");
			String msg = resultObject.getString("msg");
			
			if (Response.SUCCESS.getCode().equals(code)) {
				//返回参数拼接（删除resultObject对象中的code和msg再返回）
				resultObject.remove("code");
				resultObject.remove("msg");
				
				resultMappingEntity = Result.responseBody(code, msg, resultObject);
			}
			else {
				resultMappingEntity = Result.responseBody(code, msg);
			}			
			
		} catch(Exception e) {
			e.printStackTrace();
			//异常
			resultMappingEntity = Result.responseBody(Response.RUNTIME_ERROR.getCode(), Response.RUNTIME_ERROR.getMsg(), e.getMessage());
		}
		return resultMappingEntity.toString();
	}
	
	/**
	 * 服务站点查询
	 **@param servicestationid		网点id
	 * @param servicestationname	网点名称	
	 **@param description			网点描述
	 **@param businesstime			营业时间
	 **@param contactphone			联系电话
	 * @param provinceid			省id
	 * @param cityid				市id
	 * @param areaid				区id
	 **@param outletsaddr			网点地址
	 **@param longitude				经度
	 **@param latitude				维度
	 **@param createtime			添加时间
	 **@param updatetime			最后修改时间
	 **@param operid				操作id
	 **@param validflag				有效标志
	 * @return
	 */
	@RequestMapping(value="/ServiceStationSelect",produces={"application/json;charset=utf-8"})

	public String servicestationselect(
		 	@RequestParam(value="servicestationname", required=false) String servicestationname,
			@RequestParam(value="provinceid", required=false) String provinceid,
			@RequestParam(value="cityid", required=false) String cityid,
			@RequestParam(value="areaid", required=false) String areaid) {
		//返回数据映射实体
		ResultMappingEntity resultMappingEntity = null;
		
		try {
			
			//添加反馈
			List<ServiceStation> resultObject = serviceStationService.servicestationselect(servicestationname, 
					provinceid, cityid, areaid);
			
			String code = Response.SUCCESS.getCode();
			String msg = Response.SUCCESS.getMsg();
			
			resultMappingEntity = Result.responseBody(code, msg, resultObject);
			
		} catch(Exception e) {
			e.printStackTrace();
			//异常
			resultMappingEntity = Result.responseBody(Response.RUNTIME_ERROR.getCode(), Response.RUNTIME_ERROR.getMsg(), e.getMessage());
		}
		return resultMappingEntity.toString();
	}
}
